local meta = FindMetaTable("Player")

function GetTeamSize( team )

	local teambase = GetTeamBaseT( team )
	local numply = 0
	
	for k,v in pairs(player.GetAll()) do
		if v:GetTeamBase() == teambase then
			numply = numply + 1
		end
	end
	
	return numply
	
end

function GetTeamBaseT( team )

	local base = false

	for k,v in pairs(WWClass) do
		if team == v.Team then base = v.TeamBase break end
		
	end
	
	return base
	
end

function GetPlayersTB( t )

	local players = {}
	
	for k,v in pairs(player.GetAll()) do
		if v:GetTeamBase() == t then
			table.insert(players, v)
		end
	end
	
	return players
	
end

function meta:IsWalking()

local walktable = {IN_FORWARD, IN_BACK, IN_MOVELEFT, IN_MOVERIGHT}

	for k,v in pairs(walktable) do
		if self:KeyDown(v) then
			return true
		end
	end
	
end

function meta:IsRunning()

local runtable = {IN_SPEED}

	for k,v in pairs(runtable) do
		if self:KeyDown(v) then
			return true
		end
	end

end

function meta:Ply2Ply( from, msg )
	
	self:ChatPrint( "(PM)" .. from:Nick() .. ": " .. msg )
	
end

function meta:GetTeamBase()

	local base = 0

	for k,v in pairs(WWClass) do
	
		if self:Team() == v.Team then base = v.TeamBase break end
		
	end
	
	return base
	
end

function meta:GetTeamName()

	for k,v in pairs(WWClass) do
	
		if self:GetTeamBase() == v.TeamBase then tname = v.TeamName break end
		
	end
	
	return tname
	
end

function meta:WWGetClass()

	for k,v in pairs(WWClass) do
	
		if self:Team() == v.Team then 
			classname = v.Class 
			break
		end
		
	end
	
	return classname
	
end

function meta:GetCredits()

	for k,v in pairs(WWClass) do
	
		if self:Team() == v.Team and v.Leader then 
			creds = self:GetNWInt("credits") 
			break 
		end
		
	end
	
	return creds
	
end

function meta:WWGetModel()

	for k,v in pairs(WWClass) do
	
		if self:Team() == v.Team then return v.Model end
		
	end
	
end

function meta:IsLeader()

	for k,v in pairs(WWClass) do
	
		if self:Team() == v.Team then return v.Leader end
		
	end
	
end

function meta:HasGene()

	for k,v in pairs(WWClass) do
		
		if self:Team() == v.Team and v.Gene then return true end
		
	end
	
end

function meta:PlaySound( sound )

	surface.PlaySound( Sound(sound) )
	
end

function meta:Print( msg )

	Msg( msg )
	
end

function GetClassWeapons( team )

	local weplist = ""

	for k,v in pairs(WWClass) do
	
		if v.Team == team then
		
			for k,v in pairs(v.Weapons) do
				
				local tempwep = WW.Weapons[v] or v
			
				weplist = weplist .. "\n" .. tempwep
				
			end
			
		end
		
	end
	
	return weplist
	
end

function GetPlyFromNick( nick )

	local ply = 0

	for k,v in pairs(player.GetAll()) do
	
		if v:Nick() == nick then ply = v break end
		
	end
	
	return ply
	
end

function SpellCheck( text )

	local ftext = string.lower(text)
	
	local RetText = " "..string.lower( text ).." "
		
	for K, V in pairs( WW.Chat.FilterWords ) do
		RetText = string.Replace( RetText, " "..K.." ", " "..V.." " )
	end
		
	RetText = string.Trim( RetText )

	local UpperText = string.upper( string.sub( RetText, 0, 1 ) )
		
	RetText = UpperText..""..string.sub( RetText, 2, string.len( RetText ) )
		
	if not string.find( string.sub( RetText, string.len( RetText ) ), "%p" ) then
		RetText = RetText.."."
	end
	
	return RetText
						
end

function OnSameTeam( p1, p2 )

	local pt1 = p1:GetTeamBase()
	local pt1 = p2:GetTeamBase()
	
	if pt1 == pt2 then return true else return false end
	
end

function ResetScores()
	
	for k,v in pairs(WW.Flavor.Scores) do
	
		WW.Flavor.Scores[k] = 0
		
	end
	
end